﻿using AutoMapper;
using MediatR;
using S.Organization.API.Application.Command.SheepFarmCommand;
using S.Organization.Domian.Model;
using S.Organization.Infrastructure;

namespace S.Organization.API.Application.CommandHandler.SheepFarmCommandHandler
{
    public class DelAllSheepFarmCommandHandler : IRequestHandler<DelAllSheepFarmCommand, int>
    {

        private readonly IBaseRepository<SheepFarmSetting> _repository;
        private readonly IMapper mapper;

        public DelAllSheepFarmCommandHandler(IBaseRepository<SheepFarmSetting> repository, IMapper mapper)
        {
            _repository = repository;
            this.mapper = mapper;
        }


        public async Task<int> Handle(DelAllSheepFarmCommand request, CancellationToken cancellationToken)
        {
            string[] id = request.ids.ToString().Split(',');
            int count = 0;
            foreach (var item in id)
            {
                count+=  await  _repository.DeleteAsync(int.Parse(item));
            }
            return count;




        }
    }
}
